package ${package.ServiceImpl};

import com.atguigu.yygh.common.result.Result;
<#--import ${package.Entity}.${entity};-->
import ${package.Mapper}.${table.mapperName};
<#if table.serviceInterface>
import ${package.Service}.${table.serviceName};
</#if>
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>()<#if table.serviceInterface>, ${table.serviceName}</#if> {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}><#if table.serviceInterface> implements ${table.serviceName}</#if> {
   @Override
   public IPage<${entity}> select${entity}List(${entity} ${table.entityPath}) {
      Page<${entity}> page = this.page(new Page<>(1, 10),
      new LambdaQueryWrapper<${entity}>()
       .eq(${entity}::getId, ${table.entityPath}.getId()));
       return page;
    }

   @Override
   @Transactional(rollbackFor = Exception.class)
   public Result delete${entity}(Long id) {
     if(this.removeById(id)){
     return Result.ok("删除成功");
     }
     return Result.fail("删除失败");
   }

   @Override
   @Transactional(rollbackFor = Exception.class)
   public Result insert${entity}(${entity} ${table.entityPath}) {
      if(this.save(${table.entityPath})){
      return Result.ok("新建成功");
      }
      return Result.fail("新建失败");
   }

   @Override
   @Transactional(rollbackFor = Exception.class)
   public Result update${entity}(${entity} ${table.entityPath}) {
      if(this.updateById(${table.entityPath})){
      return Result.ok("更新成功");
      }
      return Result.fail("更新失败");
   }
}
</#if>
